//************************************************************
//
// REGSTEP 12.  REACTION FUNCTION WITH MEDIAN CASE
//
// USING SIGMA GROWTH RATES 2 DIGIT
//
// AUTHOR: LIONEL NESTA
//
// DATASOURCE: USING final_reaction_functions.dta FROM DATASTEP 5
//
//*************************************************************


// PREAMBLE
*set processors 24

clear
clear matrix 
clear mata
set more off
set mem 600m
set matsize 800

pwd 
cd ..\RESULTS

// OPENING FILE

use ..\DATA\final_reaction_functions.dta, clear

gen case = md_case1

replace case = . if case == 1.5

replace case = . if case == 2.5

replace case = . if case == 3.5

egen temp= count(c_market_c), by(did)

drop if temp < 8

// DROPS ALL RF OUTSIDE CORNERS 1 TO 4 IN BETA-SIGMA SPACE 

collapse (p90) lnrd2_p90 = lnrd2 lnrdi2_p90 = lnrdi2 (mean) lnrd1 psm_lnrd1 psm_lnrdi1 lnrd2* mrd_sec1 mrd_sec2 mrd_sec1_fs mrd_sec2_fs c_techno_c c_market_c lnrdi1 lnk1 lny1 lnk12 LI1 LI12 lnliq_k1 lnliq_ratio1 msh1 msh12 LI2 LI22 lnrdpatsm1 patent1 lnrdi2 lnk2 lnk22 lnliq_ratio2 msh2 msh22 lnrdpatsm2 patent2 L1lnrd1 L1lnrd2 L1lnrdi1 L1lnrdi2 L1lnk1 lnliq_k2  L1lnliq_ratio1 L1msh1 L1lnrdpatsm1 L2lnrdpatsm1 L1lnrdpatsm2 L2lnrdpatsm2, by(gvkey1 year case)

drop if case == .

tabulate year, gen(year_)

egen fcid  = group(gvkey1 case)
tsset fcid year

drop if year < 1990

// IV EST

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrd2 mrd_sec2_fs)  year_* if case == 1 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3) adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_GR) replace

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = l.L1lnrd2  L1lnrdpatsm2 )  year_* if case == 2 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_GR) append

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = l3.L1lnrd2 mrd_sec2_fs )  year_* if case == 3 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_GR) append

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrd2 mrd_sec2_fs)  year_* if case == 4 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_GR) append

// OPENING FILE

use ..\DATA\final_reaction_functions.dta, clear

gen case = md_case2

replace case = . if case == 1.5

replace case = . if case == 2.5

replace case = . if case == 3.5

egen temp= count(c_market_c), by(did)

drop if temp < 8

// DROPS ALL RF OUTSIDE CORNERS 1 TO 4 IN BETA-SIGMA SPACE 

collapse (p90) lnrd2_p90 = lnrd2 lnrdi2_p90 = lnrdi2 (mean) lnrd1 psm_lnrd1 psm_lnrdi1 lnrd2* mrd_sec1 mrd_sec2 mrd_sec1_fs mrd_sec2_fs c_techno_c c_market_c lnrdi1 lnk1 lny1 lnk12 LI1 LI12 lnliq_k1 lnliq_ratio1 msh1 msh12 LI2 LI22 lnrdpatsm1 patent1 lnrdi2 lnk2 lnk22 lnliq_ratio2 msh2 msh22 lnrdpatsm2 patent2 L1lnrd1 L1lnrd2 L1lnrdi1 L1lnrdi2 L1lnk1 lnliq_k2  L1lnliq_ratio1 L1msh1 L1lnrdpatsm1 L2lnrdpatsm1 L1lnrdpatsm2 L2lnrdpatsm2, by(gvkey1 year case)

drop if case == .

tabulate year, gen(year_)

egen fcid  = group(gvkey1 case)
tsset fcid year

drop if year < 1990

// IV EST

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrd2 mrd_sec2_fs)  year_* if case == 1 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3) adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_level) append

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrdpatsm2 mrd_sec2_fs)  year_* if case == 2 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_level) append

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrd2 mrd_sec2_fs )  year_* if case == 3 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_level) append

ivreg2 lnrd1 lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1 (lnrd2 = L1lnrd2 mrd_sec2_fs)  year_* if case == 4 , robust gmm2s ffirst
outreg2 lnrd2  lnk1 lnliq_ratio1 L1lnrdpatsm1 psm_lnrd1  using RF_mean_ols_iv_psm_sigma_gr_medcase, dec(3) bdec(3)  adds(Hansen J, e(j), Hansen cp, e(jp), Kleibergen-Paap Wald F statistic, e(widstat)) tex excel word aster(se) ctitle(PSM_IV_level) append


